package contreller

import (
	"SkillTextJD2/Util"
	"SkillTextJD2/model"
	"github.com/gin-gonic/gin"
)

func Handlerinformation2(c *gin.Context) {
	Name := c.Query("Name")
	var infoList []model.Information

	// 如果 Name 为空，则查询所有数据
	db := Util.DB().Table("attractions")
	if Name != "" {
		db = db.Where("attractions_Name LIKE ?", "%"+Name+"%")
	}

	err := db.Find(&infoList).Error
	if err != nil {
		c.String(500, "数据库查询错误: "+err.Error())
		return
	}

	// 传给模板的数据结构
	c.HTML(200, "information.html", gin.H{
		"out": infoList,
	})
}
